package com.guoshengdeu.door.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guoshengdeu.door.entity.School;
import com.guoshengdeu.door.service.ISchoolService;
import com.guoshengdeu.door.util.RespResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *     前端控制器
 * </p>
 *
 * @author 861053543
 * @since 2021-7-5
 */
@Api("学校")
@RestController
@RequestMapping("/school")
public class SchoolController {

    @Autowired
    private ISchoolService schoolService;

    //查询school
    @ApiOperation("查询")
    @RequestMapping("list")
    public List<School> querySchool(){
        return schoolService.list();
    }

    //添加更新
    @ApiOperation("添加更新")
    @RequestMapping("addschool")
    public RespResult addSchool(@RequestBody School school){
        boolean saveOrUpdate = schoolService.saveOrUpdate(school);
        if (saveOrUpdate){
            return RespResult.success();
        }
        return RespResult.error("添加或更新失败");
    }

    //删除school
    @ApiOperation("删除")
    @DeleteMapping("deleschool")
    public RespResult deleSchool(int id){
        boolean removeById = schoolService.removeById(id);
        if (removeById){
            return RespResult.success();
        }
        return RespResult.error("删除失败");
    }

    //分页
    @ApiOperation("分页")
    @GetMapping("page")
    public RespResult Page(Page<School> page){
        Page<School> pages = schoolService.page(page);
        return RespResult.success(pages);
    }
}
